package api

//网络配置
import (
	db "slgw_web/application/gormdb"

	"openzbox.com/frame/echo"
	models "openzbox.com/frame/echo/models/sl_gw01"
	"openzbox.com/frame/echo/response"
)

// 修改以太网信息
func EditEthSetting(ctx echo.Context) error {
	var req models.EditEthSettingRequest
	if err := ctx.Bind(&req); err != nil {
		return response.FailResult(1, err.Error(), ctx)
	}
	db := db.GetDB()
	if req.EthSetting.ID != 0 {
		//修改
		if err := db.Model(&models.EthSetting{}).Where("id = ?", req.EthSetting.ID).Updates(req.EthSetting).Error; err != nil {
			// 处理更新错误
			return response.FailResult(1, err.Error(), ctx)

		}
	} else {
		return response.FailResult(1, "数据未传输", ctx)
	}
	return response.SuccessResultWithEmptyData(ctx)
}

// 获取以太网信息
func GetEthSettin(ctx echo.Context) error {
	//定义文章结构体切片
	ethSetting := []models.EthSetting{}
	db := db.GetDB()
	//查询所有文章,以及文章的分类Preload
	db.Find(&ethSetting)
	return response.SuccessResult(ethSetting, ctx)

}
